package com.huluobo.a2111douyindemo.video;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm_base.mvvm.base.model.BaseRepo;
import com.huluobo.mvvm_base.mvvm.bean.CommentBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.FollowBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.LikeVideoBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.VideoBeanResult;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/2/28.
 */
public class VideoRepo extends BaseRepo {
    public void getVideoList(int currentPage, int pageSize, MutableLiveData<VideoBeanResult> success,
                             MutableLiveData<String> failed) {
        apiService.getVideoList(currentPage, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoBeanResult videoBeanResult) {
                        success.setValue(videoBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void likeVideo(int videoId, MutableLiveData<LikeVideoBeanResult> success, MutableLiveData<String> failed) {
        apiService.likeVideo(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeVideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeVideoBeanResult likeVideoBeanResult) {
                        success.setValue(likeVideoBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void noLikeVideo(int videoId, MutableLiveData<LikeVideoBeanResult> success, MutableLiveData<String> failed) {
        apiService.noLikeVideo(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeVideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeVideoBeanResult likeVideoBeanResult) {
                        success.setValue(likeVideoBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void followAuth(RequestBody body, MutableLiveData<FollowBeanResult> success,
                           MutableLiveData<String> failed) {
        apiService.followAuth(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<FollowBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(FollowBeanResult followBeanResult) {
                        success.setValue(followBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getCommentByVideoId(int videoId, MutableLiveData<CommentBeanResult> success,
                                    MutableLiveData<String> failed) {
        apiService.getCommentByVideoId(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommentBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommentBeanResult commentBeanResult) {
                        success.setValue(commentBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void sendComment(RequestBody body, MutableLiveData<CommentBeanResult> success,
                            MutableLiveData<String> failed) {
        apiService.sendComment(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommentBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommentBeanResult commentBeanResult) {
                        success.setValue(commentBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
